//
//  MBUploadTitleCell.swift
//  MasterBoy
//
//  Created by kyson on 2023/10/23.
//

import Foundation
import YYText
import SnapKit


class MBUploadTitleCell: MBDCommonCell {

    var titleLabel : YYLabel!
    var subtitleLabel : YYLabel!
    var infoButton : UIButton!

    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.initialize()
    }
    
    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        
        self.initialize()
    }
    
    func initialize() {
        self.contentView.setDynamicForgroundColor()
        self.commonBackgroundView.setDynamicForgroundColor()

        titleLabel = YYLabel()
        self.contentView.addSubview(titleLabel)
        
        subtitleLabel = YYLabel()
        self.contentView.addSubview(subtitleLabel)
        
        infoButton = UIButton(frame: CGRectMake(0, 0, 10, 10))
        infoButton.contentEdgeInsets = UIEdgeInsets(top: 10, left: 10, bottom:10, right: 10)
        infoButton.setImage(UIImage(named: "ico_info"), for: .normal)
        infoButton.addTarget(self, action: #selector(infoButtonClicked), for: .touchUpInside)
        self.contentView.addSubview(infoButton)
        
        titleLabel.snp.makeConstraints { make in
            make.centerY.equalTo(self.contentView)
            make.left.equalTo(20)
        }
        
        subtitleLabel.snp.makeConstraints { make in
            make.centerY.equalTo(self.titleLabel)
            make.left.equalTo(self.titleLabel.snp.right).offset(8)
        }
        
        infoButton.snp.makeConstraints { make in
            make.centerY.equalTo(titleLabel)
            make.left.equalTo(subtitleLabel.snp.right).offset(3)
            make.size.equalTo(CGSizeMake(33, 33))
        }

    }
    
    override var cellModel: Any! {
        didSet {
            self.separateLine.isHidden = true
            
            let realCellModel = self.cellModel as! MBDUploadGroupTitleCellModel
            
            titleLabel.textLayout = realCellModel.titleLayout
            
            subtitleLabel.textLayout = realCellModel.subtitleLayout
        }
    }
    
    @objc func infoButtonClicked(){
        guard self.cellModel != nil else {
            return
        }
        let realCellModel = self.cellModel as! MBDUploadGroupTitleCellModel
        if realCellModel.tipsClickedBlock != nil {
            realCellModel.tipsClickedBlock!("")
        }
    }
    
}
